﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject;
using Meraz.Core.Repositories;
using Meraz.Core.Model;

namespace Meraz.Core.Commands
{
    public interface ISavePosterCommand {
        IPosterRepository PosterRepository { get; set; }
        Poster Execute(int postID, Alias alias);
    }
    public class SavePosterCommand : ISavePosterCommand
    {
        [Inject]
        public IPosterRepository PosterRepository { get; set; }

        public Poster Execute(int postID, Alias alias)
        {
            Poster poster = PosterRepository.GetByName(postID, alias.Name);
            if (poster == null)
            {
                poster = new Poster();
                PosterRepository.Add(poster);
                poster.Alias = alias;
                poster.PostID = postID;
                Meraz.Core.Data.MerazContext.Instance.Save();
            }
            return poster;
        }
    }
}
